<%@ page import="com.xinjie.www.service.comment.CommentServiceImpl" %>
<%@ page import="com.xinjie.www.po.Comment" %>
<%@ page import="java.util.List" %>
<%@ page import="java.sql.SQLException" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>自己帖子下的评论</title>
    <style type="text/css">
        table {
            width: 100%;
            border: 1px solid red;
            border-collapse: collapse;
        }

        th, td {
            border: 1px solid red;
        }
    </style>
</head>
<body>
<%
    int postId = Integer.parseInt(request.getParameter("PostId"));
    CommentServiceImpl commentService = new CommentServiceImpl();
    List<Comment> comments = null;
    try {
        comments = commentService.getComment(postId);
    } catch (SQLException | ClassNotFoundException e) {
        e.printStackTrace();
    }
%>
<div align="center">
    <table>
        <tr>
            <th>评论id</th>
            <th>评论人id</th>
            <th>评论内容</th>
            <th>评论时间</th>
            <th></th>
        </tr>
        <%
            for (Comment comment : comments) {
        %>
        <tr>
            <%="<td>" + comment.getCommentId() + "</td>"%>
            <%="<td>" + comment.getUserId() + "</td>"%>
            <%="<td>" + comment.getContent() + "</td>"%>
            <%="<td>" + comment.getTime() + "</td>"%>
            <%
                String commentId = comment.getCommentId() + "";
                String from = "writer";
            %>
            <td><a href="DeleteComment.jsp?commentId=<%=commentId%>&postId=<%=postId%>&identity=<%=from%>">删除</a></td>
        </tr>
        <%}%>
    </table>
    <%if (request.getSession().getAttribute("deleteSuccess") != null) {%>
    <%=request.getSession().getAttribute("deleteSuccess")%>
    <%request.getSession().removeAttribute("deleteSuccess");%>
    <% }if (request.getSession().getAttribute("deleteLose")!=null){%>
    <%=request.getSession().getAttribute("deleteLose")%>
    <%request.getSession().removeAttribute("deleteLose");%>
    <%}%>
    <a href="LookOwnPost.jsp">返回</a>
</div>
</body>
</html>
